
#include <stdio.h>
#include "APRInterface.h"
#include "debug.h"

APRInterface::APRInterface()
{
   apr_initialize();
   APRInit();
}

APRInterface::APRInterface(int *argc, const char *const **argv)
{
   if (*argv)
      apr_app_initialize(argc, argv, NULL);
   else
      apr_initialize();
   APRInit();
}

APRInterface::~APRInterface()
{
   if (isinit)
   {
      isinit = 0;
      apr_pool_clear(mp);
      apr_pool_destroy(mp);
      apr_terminate();
   }
}

void APRInterface::APRInit()
{
   isinit = 1;
   apr_status_t status;
   status = apr_pool_create(&mp, NULL);
   CheckAPRError(status);
}

#define APR_INTERFACE_ERROR_DESCRIPTION_BUFFER_SIZE 0x100

void APRInterface::Check_apr_status_t_For_Error(apr_status_t status, const char *fpretty, int line)
{
   if (status == 0) return;
   char buffer[APR_INTERFACE_ERROR_DESCRIPTION_BUFFER_SIZE];
   char *terror = apr_strerror(status, buffer, APR_INTERFACE_ERROR_DESCRIPTION_BUFFER_SIZE);
   errprintpd(terror, fpretty, line);
}
